var utils = require('../../utils/util.js');
Page({
  data: {
    currentPage: 1,
    type: 1
  },
  onLoad: function(options) {
    var that = this;
    that.setData({
      type: options.type
    }, function() {
      that.goodslist(that.data.currentPage);
    })
  },
  onShow: function(e) {

  },
  //所有的商品列表
  goodslist: function(currentPage) {
    var that = this;
    utils.showLoading();
    //1.用户，2.果农
    var url = that.data.type == 1 ? '/api/v1/member/integral_log' : '/api/v1/storemanage/integral_log';
    var param = {
      page: currentPage,
        store_id: wx.getStorageSync("userType").storeid
    };
    utils.http(url, param, function(res) {
      utils.hideLoading();
      console.log(res.datas);
      var allpost = that.data.allListData;
      if (allpost == undefined) {
        allpost = [];
      }
      for (var i in res.datas) {
        res.datas[i].number = 0;
        allpost.push(res.datas[i])
      }
      if (res.datas.length < 10) {
        that.setData({
          tishi_title: '已加载全部',
        });
      } else {
        that.setData({
          tishi_title: '加载更多',
        });
      }
      that.setData({
        allListData: allpost,
        ready: res.datas.length == 0 ? 1 : 2,
      })
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    if (that.data.ready == 2) {
      var page = that.data.currentPage + 1
      that.setData({
        currentPage: page,
      })
      that.goodslist(page)
    }
  },
})